package com.example.springinit2.controller;

import com.alibaba.fastjson.JSON;
import com.example.springinit2.model.User;
import com.example.springinit2.service.AspectService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class HelloController {

  @Resource
  private AspectService aspectService;

  @RequestMapping("/")
  public String index(ModelMap map) {
	// 加入一个属性，用来在模板中读取
	map.addAttribute("host", "http://blog.didispace.com");
	// return模板文件的名称，对应src/main/resources/templates/index.html
	return "index";
  }


  @RequestMapping(value = "/hello/{name}", method = RequestMethod.GET)
  @ResponseBody
  public String hello(@PathVariable String name) {
	List<User> user = aspectService.getUser(new User());
	System.out.println(JSON.toJSONString(user));
	return "Hello " + name;
  }
}
